import instance from '@/utils/axios.js'

function getChannelList() {
    return instance({
        url: '/v1_0/channels',
        method: 'get'
    })
}
export { getChannelList }

function getArticleList({ channel_id, timestamp }) {
    return instance({
        url: '/v1_0/articles',
        method: 'get',
        params: {
            with_top: 1,
            channel_id,
            timestamp
        }
    })
}
export { getArticleList }

function getArticleInfo(id) {
    return instance({
        url: `/v1_0/articles/${id}`,
        methdo: 'get'
    })
}
export { getArticleInfo }

function followingUser(id) {
    return instance({
        url: '/v1_0/user/followings',
        method: 'post',
        data: { target: id }
    })
}
function unfollowingUser(id) {
    return instance({
        url: `/v1_0/user/followings/${id}`,
        method: 'delete',
    })
}
export { followingUser, unfollowingUser }

function praiseUser(id) {
    return instance({
        url: '/v1_0/article/likings',
        method: 'post',
        data: { target: id }
    })
}
function unPraiseUser(id) {
    return instance({
        url: `/v1_0/article/likings/${id}`,
        method: 'delete',
    })
}
export { praiseUser, unPraiseUser }

function getSuggestionList(value) {
    return instance({
        url: 'http://toutiao-app.itheima.net/v1_0/suggestion',
        method: 'get',
        params: { q: value }
    })
}
export { getSuggestionList }

function getSearchList({ page, per_page, q }) {
    return instance({
        url: 'v1_0/search',
        method: 'get',
        params: {
            page,
            per_page,
            q
        }
    })
}
export { getSearchList }